//
//  ViewController.m
//  UI_18_SQLite
//
//  Created by 李劲成 on 16/4/1.
//  Copyright © 2016年 ljc. All rights reserved.
//

#import "ViewController.h"
#import "DataBaseHandle.h"
#import "ModelOfStudent.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIButton *Open;

@property (weak, nonatomic) IBOutlet UIButton *createTable;

@property (weak, nonatomic) IBOutlet UIButton *insertModel;

@property (weak, nonatomic) IBOutlet UIButton *updateData;

@property (weak, nonatomic) IBOutlet UIButton *deleteData;

@property (weak, nonatomic) IBOutlet UIButton *select;

@property (weak, nonatomic) IBOutlet UIButton *dropTable;

@property (weak, nonatomic) IBOutlet UIButton *close;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"%@", NSHomeDirectory());
    // Do any additional setup after loading the view, typically from a nib.
}

#pragma mark - 数据库.
- (IBAction)handleOpen:(id)sender {
    
    [[DataBaseHandle sharaDateBaseHandle] openSQLName:@"student.sqlite"];
    
}

- (IBAction)handleCreateTable:(id)sender {
    [[DataBaseHandle sharaDateBaseHandle]createTabel];
}

- (IBAction)insertModel:(id)sender {
    ModelOfStudent *model = [[ModelOfStudent alloc]init];
    model.name = @"cuixiaojiangjun";
    model.age = 20;
    model.gender = @"male";
    [[DataBaseHandle sharaDateBaseHandle] insertModel:model];
}

- (IBAction)updateModel:(id)sender {
    for (int i = 1; i < 10; i++) {
        ModelOfStudent *model = [[ModelOfStudent alloc]init];
        model.name = [NSString stringWithFormat:@"cuixiaojiangjun%d", i];
        model.age = 20;
        model.gender = @"male";
        [[DataBaseHandle sharaDateBaseHandle] updateModel:model id:i];
    }
   
}
- (IBAction)deleteModel:(id)sender {
    [[DataBaseHandle sharaDateBaseHandle] deleteModelWithID:1];
}

- (IBAction)handleSelected:(id)sender {
    [[DataBaseHandle sharaDateBaseHandle] selectWithGender:@"male"];
}

- (IBAction)handleDropTable:(id)sender {
    [[DataBaseHandle sharaDateBaseHandle] dropTable];
}

- (IBAction)closeDB:(id)sender {
    [[DataBaseHandle sharaDateBaseHandle] closeDB];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
